﻿package com.tudou.home.model.ad
{
    import com.tudou.ad.*;
    import com.tudou.events.*;
    import com.tudou.home.commands.ad.*;
    import com.tudou.home.consts.*;
    import com.tudou.model.*;
    import com.tudou.track.*;
    import org.puremvc.as3.interfaces.*;
    import org.puremvc.as3.patterns.facade.*;

    public class AdInfoProxy extends AdLoader implements IProxy
    {
        protected var data:Object;
        protected var facade:IFacade;
        public static const NAME:String = "AdInfoProxy";

        public function AdInfoProxy()
        {
            facade = Facade.getInstance();
            initListener();
            return;
        }// end function

        public function getData() : Object
        {
            return this.data;
        }// end function

        public function onRegister() : void
        {
            return;
        }// end function

        public function getProxyName() : String
        {
            return NAME;
        }// end function

        private function initListener() : void
        {
            this.addEventListener(AdLoaderEvent.COMPLETE, adCompleteHlr);
            this.addEventListener(AdLoaderEvent.SECURITY_ERROR, securityErrorHlr);
            this.addEventListener(AdLoaderEvent.IO_ERROR, ioErrorHlr);
            return;
        }// end function

        override public function load(param1:IMainInfo) : void
        {
            if (PlayerConsts.NOAD_USERS.indexOf(param1.userId) >= 0)
            {
                adData.reset();
                parseAdItemInfo(new XML("<r/>"));
                dispatchEvent(new AdLoaderEvent(AdLoaderEvent.COMPLETE));
            }
            else
            {
                AOPTracker.getInst().addNodeLog(NodeLog.ADINFO_REQUEST_START);
                super.load(param1);
            }
            return;
        }// end function

        public function sendNotification(param1:String, param2:Object = null, param3:String = null) : void
        {
            facade.sendNotification(param1, param2, param3);
            return;
        }// end function

        private function ioErrorHlr(event:AdLoaderEvent) : void
        {
            AOPTracker.getInst().addNodeLog(NodeLog.ADINFO_REQUEST_ERROR);
            return;
        }// end function

        private function securityErrorHlr(event:AdLoaderEvent) : void
        {
            AOPTracker.getInst().addNodeLog(NodeLog.ADINFO_REQUEST_ERROR);
            return;
        }// end function

        public function setData(param1:Object) : void
        {
            this.data = param1;
            return;
        }// end function

        public function onRemove() : void
        {
            return;
        }// end function

        private function adCompleteHlr(event:AdLoaderEvent) : void
        {
            AOPTracker.getInst().addNodeLog(NodeLog.ADINFO_REQUEST_COMPLETE);
            sendNotification(AdCommandSet.ADINFO_LOAD_COMPLETE);
            return;
        }// end function

        override protected function parseAdItemInfo(param1:XML) : void
        {
            super.parseAdItemInfo(param1);
            return;
        }// end function

    }
}
